<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'youzhiyuan-pos-client',
  data () {
    return {}
  },
  mounted () {
    if (window.location.href.indexOf('sub=1') > -1) {
      window.document.title = window.document.title + '-副屏'
      // 切换到副屏状态
      console.log(this.$route)
      if (this.$route.path !== '/secondary') {
        this.$router.push('/secondary')
      }
    } else {
      window.addEventListener('beforeunload', e => this.handleBeforeunload(e))
    }
  },
  methods: {
    handleBeforeunload (e) {
      console.log('handleBeforeunload')
      if (process.env.NODE_ENV === 'production') {
        this.$store.dispatch('userLogout')
      }
    }
  },
  destroyed () {
    window.removeEventListener('beforeunload', e => this.handleBeforeunload(e))
  }
}
</script>

<style>
html,
body,
#app {
  width: 100%;
  height: 100%;
  max-height: 100%;
  font-family: "WenQuanYi Micro Hei", "Microsoft YaHei", "Helvetica Neue",
  Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", sans-serif;
  font-size: 14px;
  user-select: none;
}

body {
  margin: 0;
}
</style>
